<?php
defined('DT_ADMIN') or exit('Access Denied');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=<?php echo DT_CHARSET;?>"/>
<title>管理中心 - <?php echo $DT['sitename']; ?> - V<?php echo DT_VERSION; ?> R<?php echo DT_RELEASE;?></title>
<meta name="robots" content="noindex,nofollow"/>
<meta name="generator" content="DESTOON B2B - www.destoon.com"/>
<meta http-equiv="x-ua-compatible" content="IE=8"/>
<link rel="shortcut icon" type="image/x-icon" href="<?php echo DT_STATIC;?>favicon.ico"/>
<link rel="bookmark" type="image/x-icon" href="<?php echo DT_STATIC;?>favicon.ico"/>
<?php if(!DT_DEBUG) { ?><script type="text/javascript">window.onerror= function(){return true;}</script><?php } ?>


<link href="/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/plugins/bootstrap/css/bootstrap-notify.css" rel="stylesheet">
<link href="/plugins/bootstrap/css/styles/alert-bangtidy.css" rel="stylesheet">
<link href="/plugins/bootstrap/css/styles/alert-blackgloss.css" rel="stylesheet">
<link href="/plugins/bootstrap/css/styles/alert-notification-animations.css" rel="stylesheet">
<link href="/plugins/bootstrap/css/bootstrap-timepicker.min.css" rel="stylesheet">

<link rel="stylesheet" href="admin/image/style.css" type="text/css"/>
<style>
    table {
        border-collapse: separate;
        border-spacing: 1px;
    }
    
    .btn { padding: 2px 6px; font-size:12px}
    img {    vertical-align: initial;}
</style>

<script type="text/javascript" src="<?php echo DT_STATIC;?>lang/<?php echo DT_LANG;?>/lang.js"></script>
<script type="text/javascript" src="<?php echo DT_STATIC;?>file/script/config.js"></script>
<script type="text/javascript" src="/plugins/bootstrap/js/jquery-1.11.3.min.js"></script>
<!--
<script type="text/javascript" src="<?php echo DT_STATIC;?>file/script/jquery.js"></script>
-->
<script type="text/javascript" src="<?php echo DT_STATIC;?>file/script/common.js"></script>
<script type="text/javascript" src="<?php echo DT_STATIC;?>file/script/admin.js"></script>

<script type="text/javascript" src="/plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/plugins/bootstrap/js/bootstrap-notify.js"></script>
<script type="text/javascript" src="/plugins/bootstrap/js/bootstrap-timepicker.js"></script>
<script type="text/javascript" src="/plugins/bootstrap/js/bootbox.min.js"></script>    
<script type="text/javascript" src="/plugins/home/js/theapplication.js"></script>
<script type="text/javascript" src="/plugins/home/js/thevalidation.js"></script>
<script type="text/javascript" src="/plugins/home/js/thestring.js"></script>

<script>
     function CheckEmpty( vId, vEmptyMessage )
    {
        if( $(vId).val().trim() == '') {
                theApplication.showError(vEmptyMessage);
                $(vId).focus();
                return false;
        }
        return true;
    }
    
    function CheckMinMaxLength( vId, vMinLen, vMaxLen, vCheckMessage )
    {
        if( ($(vId).val().trim().length < vMinLen) ||
             ($(vId).val().trim().length > vMaxLen) ) {
            theApplication.showError(vCheckMessage);
            $(vId).focus();
            return false;
        }
        return true;
    }
</script>
</head>
<body>
<div id="msgbox" onmouseover="closemsg();" style="display:none;"></div>
<?php dmsg();
show_menu($menus);
?>

<form method="post" action="?">
<input type="hidden" name="file" value="<?php echo $file;?>"/>
<div class="tt">行业分类管理</div>
<table cellpadding="2" cellspacing="1" class="tb">
<tr>    
    <th>排序</th>
    <th>行业名称</th>
    <th>操作</th>
</tr>
<?php foreach($fenleis as $k=>$v) {?>
<tr onmouseover="this.className='on';" onmouseout="this.className='';" align="center">
    <td><input name="right[<?php echo $v['fid'];?>][displayorder]" type="text" id="displayorder<?php echo $v['fid'];?>" size="3" value="<?php echo $v['displayorder'];?>"/></td>
    <td>
    <div  style="margin-left: 20px;text-align:left">
        <span class="tree-expanded" style="width:14px; height:16px;margin-top:4px;display:inline-block;"></span>
        <span class="tree-folder-open"  style="width:16px; height:16px;margin-top:4px;display:inline-block;"></span>
        <span><?php echo $v['f_cat_name'];?></span>
    </div>
</td>
<td>
    <div style="text-align:center">
        <div onclick="onEditCategory('<?php echo $v['fid'];?>', '<?php echo $v['f_cat_name'];?>', '0');" style="cursor:pointer;float:left;margin-left:10px" > 修改 </div> 
        <div style="float:left;" > &nbsp; |&nbsp; </div>
        <div onclick="onDeleteCategory(<?php echo $v['fid'];?>)"  style="cursor:pointer;float:left;" > 删除 </div>
    </div>
</td>
</tr>
<?php 
	foreach($v['fenleiz'] as $k1=>$v1) {?>
            <tr onmouseover="this.className='on';" onmouseout="this.className='';" align="center">
		<td><input name="right[<?php echo $v1['fid'];?>][displayorder]" type="text" size="3" value="<?php echo $v1['displayorder'];?>" id="f_cat_sm<?php echo $v1['fid'];?>"/></td>
		<td>
                    
                    <div  style="margin-left: 60px;text-align:left">
                        <span class="tree-file"  style="width:16px; height:16px;margin-top:4px;display:inline-block;"></span>
                        <span><?php echo $v1['f_cat_name'];?></span>
                    </div>
                </td>
                <td>
                    <div style="text-align:center">
                        <div onclick="onEditCategory('<?php echo $v1['fid'];?>', '<?php echo $v1['f_cat_name'];?>', '<?php echo $v['fid'];?>')" style="cursor:pointer;float:left; margin-left:10px" > 修改 </div> 
                        <div style="float:left;" > &nbsp; |&nbsp; </div>
                        <div onclick="onDeleteCategory(<?php echo $v1['fid'];?>)"  style="cursor:pointer;float:left;" > 删除 </div>
                    </div>
                </td>
            </tr>
<?php
	}
}
?>
    <tr>
        <td> 
        </td>
        <td height="30" colspan="4">
            <input type="submit" name="submit" id="updateorder" value="更新排序" class="btn"/>&nbsp;&nbsp;
            <button name="add" id="add" class="btn" onclick="onAddCategory();return false;" >添加行业</button>
        </td>
    </tr>

</table>
</form>



    <!-- zhifu modal begin -->
    <div class="modal fade" id="category-modal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog" style="margin-top:60px">
            <div class="modal-content" style="background:#2d8ce0">
                <div style="text-align:center;margin-top:10px;margin-bottom:10px; font-weight:bold">
                    <span class="yj-font-m" id="category_title" style="font-size:16px">添加行业分类</span>
                </div>
                <div class="modal-body" style="background: #ffffff; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px;">
                    <div class="row" style="padding:3px;">
                        <div class="col-xs-8 col-xs-offset-2" style="text-align:center">
                           <span class="p-bold">父分类：</span>
                        
                            <select id="category_parent" name="category_parent" style="width:130px">
                                <option value="0">大分类</option>
                                <?php foreach($fenleis as $k=>$v) {?>
                                <option value="<?php echo $v['fid'];?>"><?php echo $v['f_cat_name']; ?></option>
                                <?php }?>
                            </select>
                        </div>
                        <div class="col-xs-2">
                           
                        </div>
                    </div>
                    <div class="row" style="padding:3px;">
                        <div class="col-xs-8 col-xs-offset-2" style="text-align:center">
                           <span class="p-bold">分类名：</span>
                           <input type="text" id="category_name" name="category_name"  style="width:130px"></input>
                        </div>
                        <div class="col-xs-2">
                           
                        </div>
                    </div>
                    <div class="row" style="background-color:#eee;height:1px;padding:1px;margin-top:8px">
                        <div class="col-xs-12">
                        </div>
                    </div>
                    <div class="row" style="padding:3px; padding-top:15px">
                        <div class="col-xs-2">
                           
                        </div>
                        <div class="col-xs-8" style="text-align:center">
                           <button name="okbutton" id="okButton" class="btn" onclick="onOK();return false;" >确认</button>&nbsp;&nbsp;&nbsp;
                           <button name="cancelbutton" id="cancelButton" class="btn" onclick="onCancel();return false;" >取消</button>
                        </div>
                        <div class="col-xs-2">
                           
                        </div>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    
    
    <div class='notifications top-right'></div>
    <div class='notifications bottom-right'></div>
    <div class='notifications top-left'></div>
    <div class='notifications bottom-left'></div>
    <div class='notifications bottom-center'></div>
    
    <input type="hidden" id="category_id" name="category_id" ></input>
    
    <!-- zhifu modal end -->





<script type="text/javascript">Menuon(0);</script>
<?php if(isset($update)) { ?>
<script type="text/javascript">window.parent.frames[0].location.reload();</script>
<?php } ?>
<br/>
<script>
    function onAddCategory()
    {
        $('#category_title').text("添加行业分类");
        $('#category_parent').val(0).prop('selected', true);
        $('#category_name').val('');
        $('#category_id').val('');
        $('#category_parent').css("background-color", "white"); 
        $('#category_parent').attr("disabled",false); 
        $('#category-modal').modal('show');
    }
    
     function onEditCategory(categoryId, categoryName, parentCategoryId){
        $('#category_title').text("修改行业分类");
        
        $('#category_id').val( categoryId );
        $('#category_name').val( categoryName );
        $('#category_parent').val( parentCategoryId );
        $('#category_parent').attr("disabled",true); 
        $('#category_parent').css("background-color", "lightgray"); 
        $('#category-modal').modal('show');       
    }
    
    function onDeleteCategory(id){
        var delschoice=confirm("您确认要删除吗？", function() { }, null);
        if(delschoice){
            $.post(AJPath, 'action=filte&type=del&categoryId='+id, function(data) {
                alert(data);
                window.location.reload();
            });
        }
    }
    
    function onOK()
    {
        var parentId =  $('#category_parent').val();
        var categoryText = $('#category_name').val();        
        var categoryId = $('#category_id').val();
        
        if( CheckEmpty("#category_name", "请输入分类名称") == false ) return;
        if( CheckMinMaxLength("#category_name", 0, 250, "请输入20文字以下分类名称") == false ) return;
        
        if( categoryId == '' )
        {
            // add
            $.post(AJPath, 'action=filte&type=add&categoryId='+categoryId+'&parentId='+ parentId+'&category_name='+categoryText, function(data) {
                if(data=='添加分类成功！！'){
                    window.location.reload();
                }
                else
                {
                    alert(data);
                }
            });
        }
        else
        {
            // edit
            $.post(AJPath, 'action=filte&type=edit&categoryId='+categoryId+'&parentId='+ parentId+'&category_name='+categoryText, function(data) {
                if(data=='修改分类成功！！'){
                    window.location.reload();
                }
                else
                {
                    alert(data);
                }
            });
        }
    }
    
    function onCancel()
    {
        $('#category-modal').modal('hide');
    }
   
   
</script>
<?php include tpl('footer');?>